from PySide6.QtSvg import QSvgRenderer
from PySide6.QtGui import QPixmap, QImage, QPainter

def svg_to_pixmap(svg_path: str, size: QSize) -> QPixmap:
    """把 SVG 文件渲染成 QPixmap；只要 QtSvg 模块存在就不会空。"""
    renderer = QSvgRenderer(svg_path)
    if not renderer.isValid():
        return QPixmap()          # 这里再空就是文件本身损坏或路径错

    pm = QPixmap(size)
    pm.fill(Qt.transparent)
    painter = QPainter(pm)
    renderer.render(painter)    # 真正栅格化
    painter.end()
    return pm

# 使用
pm = svg_to_pixmap(":/icons/foo.svg", QSize(64, 64))
label.setPixmap(pm)